package com.hb.medical_research_system.controller;

import com.hb.medical_research_system.common.Results;
import com.hb.medical_research_system.entity.User;
import com.hb.medical_research_system.entity.dto.UserDTO;
import com.hb.medical_research_system.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "登录注册")
@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    private final LoginService loginService;


    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    /**
     * 用户登录
     * @param user
     * @return
     */
    @ApiOperation("用户登录接口")
    @PostMapping()
    public Results login(@RequestBody UserDTO user){
       return loginService.login(user);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @ApiOperation("用户注册接口")
    @PostMapping ("/register")
    public Results register(@RequestBody UserDTO user){
        return loginService.register(user);
    }

    /**
     * 用户注册并登录
     * @param user
     * @return
     */
    @ApiOperation("用户注册并登录接口")
    @PostMapping("/register2")
    public Results register2(@RequestBody UserDTO user){
        return loginService.register2(user);
    }


}
